package com.appbee.core.client.htmleditor;

import javax.inject.Inject;

import com.appbee.core.client.htmleditor.toolbar.RichTextToolbar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.Widget;

public class HtmlEditor extends Composite implements LeafValueEditor<String>
{

	private static HtmlEditorUiBinder uiBinder = GWT
			.create(HtmlEditorUiBinder.class);

	interface HtmlEditorUiBinder extends UiBinder<Widget, HtmlEditor>
	{
	}

	@UiField(provided = true)
	RichTextToolbar toolbar;
	
	@UiField
	RichTextArea editor;

	@Inject
	public HtmlEditor(RichTextToolbar toolbar)
	{
		this.toolbar = toolbar;
		initWidget(uiBinder.createAndBindUi(this));
		toolbar.setRichText(editor);
	}
	
	public String getHtml()
	{
		return editor.getHTML();
	}
	
	public void setHtml(SafeHtml html)
	{
		editor.setHTML(html);
	}
	
	public void addToolbarWidget(Widget w)
	{
		toolbar.addToolbarWidget(w);
	}

	@Override
	public void setValue(String value)
	{
		editor.setHTML(value);
	}

	@Override
	public String getValue()
	{
		return editor.getHTML();
	}

	@Override
	public void setWidth(String width)
	{
		editor.setWidth(width);
		super.setWidth(width);
	}
	
	public void setEditorHeight(String height)
	{
		editor.setHeight(height);
	}
	
	public void setEditorStyleName(String styleName)
	{
		editor.setStyleName(styleName);
	}
	@Override
	public void addStyleName(String styleName)
	{
		
		super.addStyleName(styleName);
	}
	
	public void setToolbarStyleName(String styleName)
	{
		toolbar.setStyleName(styleName);
	}
	

}
